package org.example.springboot.dao;

import org.apache.ibatis.annotations.*;
import org.example.springboot.model.Customers;
import org.example.springboot.model.Items;

import java.util.List;

@Mapper
public interface CustomersMapper {

    @Insert("insert into customers(enterprise_code, address, bank_name, bank_account, invoice_number, company_phone, description, customer_name, contact_person, contact_phone, customer_type) values (#{enterpriseCode},#{address},#{bankName}, #{bankAccount}, #{invoiceNumber}, #{companyPhone}, #{description}, #{customerName}, #{contactPerson}, #{contactPhone}, #{customerType})")
    int insertCustomer(@Param("enterpriseCode") String enterpriseCode, @Param("address") String address, @Param("bankName") String bankName, @Param("bankAccount") String bankAccount, @Param("invoiceNumber") String invoiceNumber, @Param("companyPhone") String companyPhone, @Param("description") String description, @Param("customerName") String customerName, @Param("contactPerson") String contactPerson, @Param("contactPhone") String contactPhone, @Param("customerType") String customerType);

    @Select("select * from customers")
    List<Customers> getAllCustomer();

    @Select("select * from customers " + "where enterprise_code like CONCAT('%', #{keyword}, '%') " + "or customer_name like CONCAT('%', #{keyword}, '%')"+ "or contact_person like CONCAT('%', #{keyword}, '%')"+ "or contact_phone like CONCAT('%', #{keyword}, '%')"+ "or customer_type like CONCAT('%', #{keyword}, '%')")
    List<Customers> findCustomerByKeyword(@Param("keyword")String keyword);

    @Delete("delete from customers where enterprise_code = #{enterpriseCode}")
    void deleteCustomerByCode(@Param("enterpriseCode")String enterpriseCode);

    @Select("select * from customers where enterprise_code = #{enterpriseCode}")
    Customers findCustomerByCode(String enterpriseCode);
}
